From 245de756393f82f8bc909b368eb6d89bf9361b6f Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sat, 19 Aug 2017 04:19:37 +0200 Subject: [PATCH] babl: add babl_space_rgb_matrix --- babl/babl-space.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ babl/babl-space.h | 2 ++ babl/babl.h | 17 ++++++++++++- 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/babl/babl-space.c b/babl/babl-space.c index 37c40ad..a4d695c 100644 --- a/babl/babl-space.c +++ b/babl/babl-space.c @@ -143,6 +143,70 @@ babl_space (const char *name) return NULL; } +const Babl * +babl_space_rgb_matrix (const char *name, + double rx, double gx, double bx, + double ry, double gy, double by, + double rz, double gz, double bz, + const Babl *trc_red, + const Babl *trc_green, + const Babl *trc_blue) +{ + int i=0; + static BablSpace space; + space.instance.class_type = BABL_SPACE; + space.instance.id = 0; + + space.xr = rx; + space.yr = gx; + space.xg = bx; + space.yg = ry; + space.xb = gy; + space.yb = by; + space.xw = rz; + space.yw = gz; + space.pad = bz; + space.trc[0] = trc_red; + space.trc[1] = trc_green?trc_green:trc_red; + space.trc[2] = trc_blue?trc_blue:trc_red; + + for (i = 0; space_db[i].instance.class_type; i++) + { + int offset = ((char*)&space_db[i].xr) - (char*)(&space_db[i]); + int size = ((char*)&space_db[i].trc) + sizeof(space_db[i].trc) - ((char*)&space_db[i].xr); + + if (memcmp ((char*)(&space_db[i]) + offset, ((char*)&space) + offset, size)==0) + { + return (void*)&space_db[i]; + } + } + if (i >= MAX_SPACES-1) + { + babl_log ("too many BablSpaces"); + return NULL; + } + /* transplany matrixes */ + babl_space_compute_matrices (&space_db[i]); + memcpy (space.RGBtoXYZ, &space.xr, sizeof (space.RGBtoXYZ)); + babl_matrix_invert (space.RGBtoXYZ, space.XYZtoRGB); + + space_db[i]=space; + space_db[i].instance.name = space_db[i].name; + if (name) + sprintf (space_db[i].name, "%s", name); + else + sprintf (space_db[i].name, "space-%.4f,%.4f_%.4f,%.4f_%.4f_%.4f,%.4f_%.4f,%.4f_%s,%s,%s", + rx, gx, bx, + ry, gy, by, + rz, gz, bz, + babl_get_name (space.trc[0]), + babl_get_name(space.trc[1]), babl_get_name(space.trc[2])); + + + return (Babl*)&space_db[i]; +} + + const Babl * babl_space_rgb_chromaticities (const char *name, double wx, double wy, diff --git a/babl/babl-space.h b/babl/babl-space.h index e387d4f..2b2a883 100644 --- a/babl/babl-space.h +++ b/babl/babl-space.h @@ -40,6 +40,8 @@ typedef struct double xb; // blue primary chromaticity double yb; + double pad; // for when the numbers represent a matrix + const Babl *trc[3]; char name[128]; diff --git a/babl/babl.h b/babl/babl.h index b635c00..31d58dc 100644 --- a/babl/babl.h +++ b/babl/babl.h @@ -106,7 +106,7 @@ const Babl * babl_trc_gamma (double gamma); const Babl * babl_space (const char *name); /** - * babl_space_new: + * babl_space_rgb_chromaticities: * * Creates a new RGB matrix color space definition with the specified * white point wx, wy, primary chromaticities rx,ry,gx,gy,bx,by and @@ -122,6 +122,21 @@ const Babl * babl_space_rgb_chromaticities (const char *name, const Babl *trc_green, const Babl *trc_blue); +/** + * babl_space_rgb_chromaticities: + * + * Creates a new RGB matrix color space definition using a precomputed + * D50 adapted 3x3 matrix, as possibly read from an ICC profile. + */ +const Babl * +babl_space_rgb_matrix (const char *name, + double rx, double gx, double bx, + double ry, double gy, double by, + double rz, double gz, double bz, + const Babl *trc_red, + const Babl *trc_green, + const Babl *trc_blue); + const double * babl_space_get_rgbtoxyz (const Babl *space); void babl_space_to_xyz (const Babl *space, const double *rgb, double *xyz); void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb); -- 2.30.2